/**
 * @author 陶锦恒
 * @since 2023/06/19 09:51
 */
package com.cskaoyan.service;

import com.cskaoyan.domain.MarketCategory;
import com.cskaoyan.domain.MarketCategoryExample;
import com.cskaoyan.mapper.MarketCategoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryServiceImpl implements CategoryService{
    @Autowired
    MarketCategoryMapper marketCategoryMapper;
    @Override
    public MarketCategory getCategoryById(Integer id) {
        MarketCategory marketCategory = marketCategoryMapper.selectByPrimaryKey(id);
        return marketCategory;
    }

    @Override
    public List<MarketCategory> getCategoryByPid(Integer pid) {
        MarketCategoryExample marketCategoryExample = new MarketCategoryExample();
        marketCategoryExample.createCriteria().andPidEqualTo(pid);
        List<MarketCategory> marketCategories = marketCategoryMapper.selectByExample(marketCategoryExample);
        return marketCategories;
    }

    @Override
    public List<MarketCategory> getCategories() {
        MarketCategoryExample marketCategoryExample = new MarketCategoryExample();
        marketCategoryExample.createCriteria().andLevelEqualTo("L2");
        List<MarketCategory> marketCategories = marketCategoryMapper.selectByExample(marketCategoryExample);
        return marketCategories;
    }

    @Override
    public MarketCategory getCategoryByname(String s) {
        MarketCategoryExample marketCategoryExample = new MarketCategoryExample();
        marketCategoryExample.createCriteria().andNameEqualTo(s);
        List<MarketCategory> marketCategories = marketCategoryMapper.selectByExample(marketCategoryExample);
        MarketCategory marketCategory = marketCategories.get(0);
        return marketCategory;
    }
}
